package com.akbar.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultUtil<T> {
    private Integer code;    // 1成功，0和其它数字为失败
    private String msg;      //错误信息
    private T data;          //数据

    public static final Integer SUCCESS_CODE = 1;
    public static final Integer ERROR_CODE = 0;

    // 成功
    public static <T> ResultUtil<T> success(T data) {
        return new ResultUtil<>(SUCCESS_CODE, "success", data);
    }

    public static <T> ResultUtil<T> success(String msg, T data) {
        return new ResultUtil<>(SUCCESS_CODE, msg, data);
    }


    // 错误
    public static <T> ResultUtil<T> error(String message) {
        return new ResultUtil<>(ERROR_CODE, message, null);
    }

    // 返回状态码，比如401，403等
    public static <T> ResultUtil<T> error(int responseCode, String message) {
        return new ResultUtil<>(responseCode, message, null);
    }
}
